package com.dc.free.controller;

import com.alibaba.fastjson.JSONObject;
import com.dc.free.util.ControllerUtil;
import com.dc.free.util.StatusUtil;
import com.jfinal.core.Controller;
import com.jfinal.log.Log;

public abstract class BaseController extends Controller {
	
	protected final Log log = Log.getLog(this.getClass());
	protected JSONObject data = new JSONObject(); //处理后数据

	public StatusUtil renderStatus(int code, String msg, String stack, Object data) {
		return ControllerUtil.renderStatus(this, code, msg, stack, data);
	}
	
	public StatusUtil renderStatus(int code, String stack, Object data) {
		return renderStatus(code, "", stack, data);
	}
	
	public StatusUtil renderStatus(String stack, Object data) {
		return renderStatus(StatusUtil.SUCCESS, "", stack, data);
	}
	
	public StatusUtil renderStatus(int code) {
		return renderStatus(code, null, null, null);
	}
	
	public StatusUtil renderStatus(Object data) {
		return renderStatus("", data);
	}
	
	public StatusUtil renderStatus() {
		return renderStatus("");
	}
	
	public JSONObject getParameters() {
		return ControllerUtil.getParameters(this);
	}
	
	public JSONObject getParameterName() {
		return ControllerUtil.getParameterName(this);
	}

	public void addData(String key, String value) {
		this.data.put(key, value);
	}
	
	public void setUser(Object user) {
		ControllerUtil.setUser(this, user);
	}
	
	public <T> T getUser() {
		return ControllerUtil.getUser(this);
	}
	
	public boolean isExistUser() {
		return ControllerUtil.isExistUser(this);
	}
	
}
